package com.factory.test.activity;

import android.os.Bundle;
//import android.os.yx.YxDeviceManager2;
import android.widget.CompoundButton;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.factory.test.base.BaseTestActivity;
import com.factory.test.base.MyApplication;
import com.factory.test.R;
import com.factory.test.databinding.ActivityGpioBinding;
import com.factory.test.util.gpio.GpioController;


/**
 * GPIO 输入输出
 */
public class GpioActivity extends BaseTestActivity {

    private ActivityGpioBinding binding;

    private GpioController gpioController;
//    YxDeviceManager2 yx;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_gpio);
//        yx = YxDeviceManager2.getInstance(this);



        gpioController = MyApplication.getBaseFactoryTest().getDeviceGpioController();

        binding.gpio0.setChecked(gpioController.getIO_0() == 1);
        binding.gpio5.setChecked(gpioController.getIO_5() == 1);

        binding.gpio0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                gpioController.setIO_0(isChecked ? 1 : 0);
            }
        });

        binding.gpio5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                gpioController.setIO_5(isChecked ? 1 : 0);
            }
        });
    }
}
